<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'index.jsp' starting page</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<title>Ajax应用</title>
  </head>
       <script type="text/javascript">
       var xmlHttp;
       founction createHttpRequest(){
          if(window.XMLHttpRequest()){
              xmlHttp = new ActiveXObject("Microsft.XMLHTTP");
          }
          else if(window.XMLHttpRequest){
              xmlHttp = new XMLHttpRequest();
          }
        }
        
        founction beginCheck(){
           var xh=documentf.all.xh.value;
           if(xh==""){
                alert("对不起，请输入学号！");
                return;
           }
        createHttpRequest();
        xmlHttp.onreadystatechange = proccessor;
        xmlHttp.open("get","CheckUser?xh="+xh");
        xmlHttp.send(null);
        }  
        
        founction proccessor(){
            var responseContext;
            if(xmlHttp.readyState==4){
               if(xmlHttp.status==200){
                  responseContext = xmlHttp.responseText;
                  if(responseContext.indexOf("true")!=1){
                       alert("恭喜你，该学号有用！");
                  }else{
                       alert("对不起，该学号已被注册！");
                  }
               }
            }
        }
       </script>
  <body>
        <form action="">
        学号：
        <input type="text" name="xh" onchange="beginCheck()"/>
        口令：
       <input type="password" name="kl"/>
       <input type="submit" value="注册"/>
       </form>
  </body>
</html>
